﻿angular.module('picShare').controller('uploadImageController', function ($scope, httpRequestSvc, userDataSvc,safeApply) {

//    console.log("from controller " + $scope.$id);

    $scope.uploadImageTitle = "Upload Image Page";

    $scope.addAlbum = function () {
        var albumName = $scope.addAlbumName;
        userDataSvc.pushNewAlbum(albumName);
        $scope.addAlbumName = "";
    };

    $scope.uploadImage = function () {
        var inputImage = $('form')[0];
        var formData = new FormData(inputImage);
        var albumName = $scope.albName.name;
        var uploaderName = userDataSvc.user.userName;

//        console.log(albumName);
        httpRequestSvc.postImage("http://localhost:26666/api/image/add-image?userName=" + uploaderName + "&albumName=" + albumName, formData).done(
            function (data) {
//                console.log(data);
                $scope.upladedMessage = data;
                safeApply($scope);
            }, function (data) {
                $scope.upladedMessage = "Not Uploaded";
                safeApply($scope);
            });

    };

});